program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  arr=array [0..1] of integer;

var
  E, V, i, j, count, x, y, col:integer;
  color:array of integer;
  edge:array of arr;

begin
  readln(E, V);
  setlength(edge, E);
  setlength(color, V);
  for i := 1 to E do
    readln(edge[i][0], edge[i][1]);
  for i := 1 to V do
    color[i]:=i;

  count:=V;
  for i := 1 to E do
  begin
    x:=edge[i][0];
    y:=edge[i][1];
    if (color[x]<>color[y]) then
    begin
      count:=count-1;
      col:=color[x];
      for j := 1 to V do
        if (color[j]=col) then
          color[j]:=color[y];
    end;
  end;
  writeln(count);
  for i := 1 to V do
  begin
    //writeln(i, ':');
    for j := 1 to V do
      if (color[j]=i) then
        write(j, ' ');
    writeln;
  end;
  readln;
end.

